Hệ thống xếp lịch học tín chỉ cho sinh viên CNTT trên PHP & MySQL
112.103 lượt xem;
1 <?php
2 $currDir = dirname(__FILE__);
3 require("{$currDir}/incCommon.php");
4
5 $recID = 0;
6
7 // request to save changes?
8 if(isset($_REQUEST['saveChanges'])){
9 // validate data
10 $recID = intval($_REQUEST['recID']);
11 $memberID = makeSafe(strtolower($_REQUEST['memberID']));
12 ###############################
13
14 /* for ajax requests coming from the users' area, get the recID */
15 if(is_ajax()){
16 $tableName = $_REQUEST['t'];
17 $pkValue = $_REQUEST['pkValue'];
18
19 if(!in_array($tableName, array_keys(getTableList()))) die($Translation["invalid table"]);
20
21 if(!$pkValue) die($Translation["invalid primary key"]);
22 }
23
24 if($recID){
25 $tableName = sqlValue("select tableName from membership_userrecords where recID='{$recID}'");
26 $pkValue = sqlValue("select pkValue from membership_userrecords where recID='{$recID}'");
27 }
28
29 // update ownership
30 set_record_owner($tableName, $pkValue, $memberID);
31
32 if(is_ajax()){
33 echo 'OK';
34 exit;
35 }
36
37 // redirect to member editing page
38 redirect("admin/pageEditOwnership.php?recID={$recID}");
39 exit;
40 }elseif(isset($_GET['recID'])){
41 // we have an edit request for a member
42 $recID = intval($_GET['recID']);
43 }
44
45 if(!$recID){
46 redirect("admin/pageViewRecords.php");
47 exit;
48 }
49
50 $GLOBALS['page_title'] = $Translation['edit Record Ownership'];
51 include("{$currDir}/incHeader.php");
52
53 // fetch record data to fill in the form below
54 $res = sql("select * from membership_userrecords where recID='{$recID}'", $eo);
55 if($row = db_fetch_assoc($res)){
56 // get record data
57 $tableName = $row['tableName'];
58 $pkValue = $row['pkValue'];
59 $memberID = strtolower($row['memberID']);
60 $dateAdded = @date($adminConfig['PHPDateTimeFormat'], $row['dateAdded']);
61 $dateUpdated = @date($adminConfig['PHPDateTimeFormat'], $row['dateUpdated']);
62 $groupID = $row['groupID'];
63 }else {
64 // no such record exists
65 die("<div class=\"alert alert-danger\">{$Translation["record not found error"]}</div>");
66 }
67 ?>
68
69 <div class="page-header"><h1><?php echo $Translation['edit Record Ownership']; ?></h1></div>
70
71 <form method="post" action="pageEditOwnership.php" class="form-horizontal">
72 <input type="hidden" name="recID" value="<?php echo html_attr($recID); ?>">
73 <div style="height: 1em;"></div>
74
75 <div class="form-group">
76 <label for="groupID" class="col-xs-12 col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
77 <?php echo $Translation["owner group"]; ?>
78 </label>
79 <div class="col-xs-10 col-sm-7 col-md-8 col-lg-5">
80 <?php
81 echo bootstrapSQLSelect('groupID', "select g.groupID, g.name from membership_groups g order by name", $groupID);
82 ?>
83 </div>
84 <div class="col-xs-2 col-sm-1">
85 <a class="btn btn-default" title="<?php echo html_attr($Translation['view all records by group']); ?>" href="pageViewRecords.php?groupID=<?php echo urlencode($groupID); ?>">
86 <i class="glyphicon glyphicon-chevron-right"></i>
87 </a>
88 </div>
89 </div>
90
91 <div class="form-group">
92 <label for="memberID" class="col-xs-12 col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
93 <?php echo $Translation["owner member"]; ?>
94 </label>
95 <div class="col-xs-10 col-sm-7 col-md-8 col-lg-5">
96 <?php
97 echo bootstrapSQLSelect('memberID', "select lcase(memberID), lcase(memberID) from membership_users where groupID='$groupID' order by memberID", $memberID);
98 ?>
99 <span class="help-block"><?php echo $Translation["switch record ownership"]; ?></span>
100 </div>
101 <div class="col-xs-2 col-sm-1">
102 <a class="btn btn-default" title="<?php echo html_attr($Translation['view all records by member']); ?>" href="pageViewRecords.php?memberID=<?php echo urlencode($memberID); ?>">
103 <span class="glyphicon glyphicon-chevron-right"></span>
104 </a>
105 </div>
106 </div>
107
108 <div class="form-group">
109 <label class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
110 <?php echo $Translation["record created on"]; ?>
111 </label>
112 <div class="col-sm-8 col-md-9 col-lg-6">
113 <p class="form-control-static"><?php echo $dateAdded; ?></p>
114 </div>
115 </div>
116
117 <div class="form-group">
118 <label class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
119 <?php echo $Translation["record modified on"]; ?>
120 </label>
121 <div class="col-sm-8 col-md-9 col-lg-6">
122 <p class="form-control-static"><?php echo $dateUpdated; ?></p>
123 </div>
124 </div>
125
126 <div class="form-group">
127 <label class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
128 <?php echo $Translation["table"]; ?>
129 </label>
130 <div class="col-sm-8 col-md-9 col-lg-6">
131 <p class="form-control-static">
132 <a href="pageViewRecords.php?tableName=<?php echo urlencode($tableName); ?>" title="<?php echo html_attr($Translation['view all records of table']); ?>">
133 <?php echo $tableName; ?>
134 <i class="glyphicon glyphicon-th"></i>
135 </a>
136 </p>
137 </div>
138 </div>
139
140 <div class="form-group ">
141 <label for="member username" class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
142 <div><?php echo $Translation["record data"]; ?></div>
143 </label>
144 <div class="col-sm-8 col-md-9 col-lg-6">
145 <div class="form-control-static">
146 <?php
147 // get pk field name
148 $pkField = getPKFieldName($tableName);
149
150 $res = sql("select * from `{$tableName}` where `{$pkField}`='" . makeSafe($pkValue, false) . "'", $eo);
151 if($row = db_fetch_assoc($res)){
152 ?>
153 <div style="margin-bottom: 1em;">
154 <a href="../<?php echo $tableName; ?>_view.php?SelectedID=<?php echo urlencode($pkValue); ?>&dvprint_x=1" target="_blank" class="btn btn-default">
155 <i class='glyphicon glyphicon-print'></i>
156 <?php echo $Translation["print"]; ?>
157 </a>
158 <a href="../<?php echo $tableName; ?>_view.php?SelectedID=<?php echo urlencode($pkValue); ?>" target="_blank" class="btn btn-default">
159 <i class='glyphicon glyphicon-pencil'></i>
160 <?php echo $Translation["edit"]; ?>
161 </a>
162 </div>
163
164 <table class="table table-striped table-bordered">
165 <thead>
166 <tr>
167 <th style="width: 30%"><?php echo $Translation["field name"]; ?></th>
168 <th><?php echo $Translation["value"]; ?></th>
169 </tr>
170 </thead>
171 <tbody>
172 <?php
173 foreach ($row as $field_name => $field_value){
174 $field_link = false;
175 if(@is_file("{$currDir}/../{$Translation['ImageFolder']}{$field_value}")){
176 $field_value = "<a href=\"../{$Translation['ImageFolder']}{$field_value}\" target=\"_blank\">" . html_attr($field_value) . "</a>";
177 $field_link = true;
178 }
179 ?>
180 <tr>
181 <td><?php echo $field_name; ?></td>
182 <?php if($field_link){ ?>
183 <td><?php echo $field_value; ?></td>
184 <?php }else{ ?>
185 <td><?php echo nl2br(htmlspecialchars($field_value, ENT_NOQUOTES | ENT_COMPAT | ENT_HTML401, datalist_db_encoding)); ?></td>
186 <?php } ?>
187 </tr>
188 <?php
189 }
190 ?>
191 </tbody>
192 </table>
193 <?php
194 }else{
195 ?>
196 <div class="alert alert-danger"><?php echo $Translation['record not found error']; ?></div>
197 <?php
198 }
199 ?>
200 </div>
201 </div>
202 </div>
203
204 <div class="row">
205 <div class="col-sm-8 col-sm-offset-4 col-md-9 col-md-offset-3 col-lg-6 col-lg-offset-4">
206 <button type="submit" name="saveChanges" value="1" class="hidden-xs hidden-sm btn btn-primary btn-lg">
207 <i class="glyphicon glyphicon-ok"></i>
208 <?php echo $Translation["save changes"]; ?>
209 </button>
210 <button type="submit" name="saveChanges" value="1" class="hidden-md hidden-lg btn btn-primary btn-lg btn-block">
211 <i class="glyphicon glyphicon-ok"></i>
212 <?php echo $Translation["save changes"]; ?>
213 </button>
214 </div>
215 </div>
216 </form>
217
218 <div style="height: 1em;"></div>
219
220 <style>
221 .form-control{ width: 100% !important; }
222 </style>
223
224 <?php
225 include("{$currDir}/incFooter.php");
226 ?>
2 $currDir = dirname(__FILE__);
3 require("{$currDir}/incCommon.php");
4
5 $recID = 0;
6
7 // request to save changes?
8 if(isset($_REQUEST['saveChanges'])){
9 // validate data
10 $recID = intval($_REQUEST['recID']);
11 $memberID = makeSafe(strtolower($_REQUEST['memberID']));
12 ###############################
13
14 /* for ajax requests coming from the users' area, get the recID */
15 if(is_ajax()){
16 $tableName = $_REQUEST['t'];
17 $pkValue = $_REQUEST['pkValue'];
18
19 if(!in_array($tableName, array_keys(getTableList()))) die($Translation["invalid table"]);
20
21 if(!$pkValue) die($Translation["invalid primary key"]);
22 }
23
24 if($recID){
25 $tableName = sqlValue("select tableName from membership_userrecords where recID='{$recID}'");
26 $pkValue = sqlValue("select pkValue from membership_userrecords where recID='{$recID}'");
27 }
28
29 // update ownership
30 set_record_owner($tableName, $pkValue, $memberID);
31
32 if(is_ajax()){
33 echo 'OK';
34 exit;
35 }
36
37 // redirect to member editing page
38 redirect("admin/pageEditOwnership.php?recID={$recID}");
39 exit;
40 }elseif(isset($_GET['recID'])){
41 // we have an edit request for a member
42 $recID = intval($_GET['recID']);
43 }
44
45 if(!$recID){
46 redirect("admin/pageViewRecords.php");
47 exit;
48 }
49
50 $GLOBALS['page_title'] = $Translation['edit Record Ownership'];
51 include("{$currDir}/incHeader.php");
52
53 // fetch record data to fill in the form below
54 $res = sql("select * from membership_userrecords where recID='{$recID}'", $eo);
55 if($row = db_fetch_assoc($res)){
56 // get record data
57 $tableName = $row['tableName'];
58 $pkValue = $row['pkValue'];
59 $memberID = strtolower($row['memberID']);
60 $dateAdded = @date($adminConfig['PHPDateTimeFormat'], $row['dateAdded']);
61 $dateUpdated = @date($adminConfig['PHPDateTimeFormat'], $row['dateUpdated']);
62 $groupID = $row['groupID'];
63 }else {
64 // no such record exists
65 die("<div class=\"alert alert-danger\">{$Translation["record not found error"]}</div>");
66 }
67 ?>
68
69 <div class="page-header"><h1><?php echo $Translation['edit Record Ownership']; ?></h1></div>
70
71 <form method="post" action="pageEditOwnership.php" class="form-horizontal">
72 <input type="hidden" name="recID" value="<?php echo html_attr($recID); ?>">
73 <div style="height: 1em;"></div>
74
75 <div class="form-group">
76 <label for="groupID" class="col-xs-12 col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
77 <?php echo $Translation["owner group"]; ?>
78 </label>
79 <div class="col-xs-10 col-sm-7 col-md-8 col-lg-5">
80 <?php
81 echo bootstrapSQLSelect('groupID', "select g.groupID, g.name from membership_groups g order by name", $groupID);
82 ?>
83 </div>
84 <div class="col-xs-2 col-sm-1">
85 <a class="btn btn-default" title="<?php echo html_attr($Translation['view all records by group']); ?>" href="pageViewRecords.php?groupID=<?php echo urlencode($groupID); ?>">
86 <i class="glyphicon glyphicon-chevron-right"></i>
87 </a>
88 </div>
89 </div>
90
91 <div class="form-group">
92 <label for="memberID" class="col-xs-12 col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
93 <?php echo $Translation["owner member"]; ?>
94 </label>
95 <div class="col-xs-10 col-sm-7 col-md-8 col-lg-5">
96 <?php
97 echo bootstrapSQLSelect('memberID', "select lcase(memberID), lcase(memberID) from membership_users where groupID='$groupID' order by memberID", $memberID);
98 ?>
99 <span class="help-block"><?php echo $Translation["switch record ownership"]; ?></span>
100 </div>
101 <div class="col-xs-2 col-sm-1">
102 <a class="btn btn-default" title="<?php echo html_attr($Translation['view all records by member']); ?>" href="pageViewRecords.php?memberID=<?php echo urlencode($memberID); ?>">
103 <span class="glyphicon glyphicon-chevron-right"></span>
104 </a>
105 </div>
106 </div>
107
108 <div class="form-group">
109 <label class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
110 <?php echo $Translation["record created on"]; ?>
111 </label>
112 <div class="col-sm-8 col-md-9 col-lg-6">
113 <p class="form-control-static"><?php echo $dateAdded; ?></p>
114 </div>
115 </div>
116
117 <div class="form-group">
118 <label class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
119 <?php echo $Translation["record modified on"]; ?>
120 </label>
121 <div class="col-sm-8 col-md-9 col-lg-6">
122 <p class="form-control-static"><?php echo $dateUpdated; ?></p>
123 </div>
124 </div>
125
126 <div class="form-group">
127 <label class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
128 <?php echo $Translation["table"]; ?>
129 </label>
130 <div class="col-sm-8 col-md-9 col-lg-6">
131 <p class="form-control-static">
132 <a href="pageViewRecords.php?tableName=<?php echo urlencode($tableName); ?>" title="<?php echo html_attr($Translation['view all records of table']); ?>">
133 <?php echo $tableName; ?>
134 <i class="glyphicon glyphicon-th"></i>
135 </a>
136 </p>
137 </div>
138 </div>
139
140 <div class="form-group ">
141 <label for="member username" class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label">
142 <div><?php echo $Translation["record data"]; ?></div>
143 </label>
144 <div class="col-sm-8 col-md-9 col-lg-6">
145 <div class="form-control-static">
146 <?php
147 // get pk field name
148 $pkField = getPKFieldName($tableName);
149
150 $res = sql("select * from `{$tableName}` where `{$pkField}`='" . makeSafe($pkValue, false) . "'", $eo);
151 if($row = db_fetch_assoc($res)){
152 ?>
153 <div style="margin-bottom: 1em;">
154 <a href="../<?php echo $tableName; ?>_view.php?SelectedID=<?php echo urlencode($pkValue); ?>&dvprint_x=1" target="_blank" class="btn btn-default">
155 <i class='glyphicon glyphicon-print'></i>
156 <?php echo $Translation["print"]; ?>
157 </a>
158 <a href="../<?php echo $tableName; ?>_view.php?SelectedID=<?php echo urlencode($pkValue); ?>" target="_blank" class="btn btn-default">
159 <i class='glyphicon glyphicon-pencil'></i>
160 <?php echo $Translation["edit"]; ?>
161 </a>
162 </div>
163
164 <table class="table table-striped table-bordered">
165 <thead>
166 <tr>
167 <th style="width: 30%"><?php echo $Translation["field name"]; ?></th>
168 <th><?php echo $Translation["value"]; ?></th>
169 </tr>
170 </thead>
171 <tbody>
172 <?php
173 foreach ($row as $field_name => $field_value){
174 $field_link = false;
175 if(@is_file("{$currDir}/../{$Translation['ImageFolder']}{$field_value}")){
176 $field_value = "<a href=\"../{$Translation['ImageFolder']}{$field_value}\" target=\"_blank\">" . html_attr($field_value) . "</a>";
177 $field_link = true;
178 }
179 ?>
180 <tr>
181 <td><?php echo $field_name; ?></td>
182 <?php if($field_link){ ?>
183 <td><?php echo $field_value; ?></td>
184 <?php }else{ ?>
185 <td><?php echo nl2br(htmlspecialchars($field_value, ENT_NOQUOTES | ENT_COMPAT | ENT_HTML401, datalist_db_encoding)); ?></td>
186 <?php } ?>
187 </tr>
188 <?php
189 }
190 ?>
191 </tbody>
192 </table>
193 <?php
194 }else{
195 ?>
196 <div class="alert alert-danger"><?php echo $Translation['record not found error']; ?></div>
197 <?php
198 }
199 ?>
200 </div>
201 </div>
202 </div>
203
204 <div class="row">
205 <div class="col-sm-8 col-sm-offset-4 col-md-9 col-md-offset-3 col-lg-6 col-lg-offset-4">
206 <button type="submit" name="saveChanges" value="1" class="hidden-xs hidden-sm btn btn-primary btn-lg">
207 <i class="glyphicon glyphicon-ok"></i>
208 <?php echo $Translation["save changes"]; ?>
209 </button>
210 <button type="submit" name="saveChanges" value="1" class="hidden-md hidden-lg btn btn-primary btn-lg btn-block">
211 <i class="glyphicon glyphicon-ok"></i>
212 <?php echo $Translation["save changes"]; ?>
213 </button>
214 </div>
215 </div>
216 </form>
217
218 <div style="height: 1em;"></div>
219
220 <style>
221 .form-control{ width: 100% !important; }
222 </style>
223
224 <?php
225 include("{$currDir}/incFooter.php");
226 ?>